package com.example.notification

import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Bundle
import android.widget.RemoteViews
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationCompat

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val notificationManager =
            getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://baidu.com"))
        val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)

        val notification = NotificationCompat.Builder(this).apply {
            setContentIntent(pendingIntent)
            setSmallIcon(R.drawable.ic_launcher_background)
            setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.ic_launcher_foreground))
            setAutoCancel(true)
            setContentTitle("普通通知")
            setCustomBigContentView(RemoteViews(packageName, R.layout.view_fold))
        }.build()

        notificationManager.notify(1, notification)

    }
}
